﻿using System;
using NUnit.Framework;
using Rainbow.Exceptions;
using Rainbow.ObjectFlow.Framework;
using Shouldly;

namespace Objectflow.core.tests
{
    public class ExceptionHandlingExtensions
    {
        [Test]
        public void On_workflow_should_create_new_exception_handler()
        {
            var workflow = new Workflow<string>();
            workflow.Configure().ShouldBeTypeOf<ExceptionHandler>();
        }

        [Test]
        public void On_define_should_create_new_exception_handler()
        {
            var workflow = Workflow<string>.Definition();
            workflow.Configure().ShouldBeTypeOf<ExceptionHandler>();
        }

        [Test]
        public void On_workflow_should_create_new_exception_handler_every_call()
        {
            var workflow = new Workflow<string>();
            workflow.Configure().ShouldNotBe(workflow.Configure());
        }

        [Test]
        public void On_define_should_create_new_exception_handler_every_call()
        {
            var workflow = Workflow<string>.Definition();
            workflow.Configure().ShouldNotBe(workflow.Configure());
        }

        [Test]
        public void When_should_return_original_workflow()
        {
            var workflow = new Workflow<string>();
            int invoked = 0;
            workflow.Configure().On<Exception>(()=> invoked++).When<string>().ShouldBe(workflow);
        }

        [Test]
        public void When_should_set_exception_handler()
        {
            var workflow = new Workflow<string>();
            int invoked = 0;
            workflow.Configure().On<Exception>(() => invoked++).When<string>();

            workflow.ExceptionHandler.ShouldNotBe(null);
        }

    }
}